#include "GlobalContext.h"

namespace SE
{
	void GlobalContext::Start()
	{
		auto& instance = Get();

		instance.mConfigManager		= ConfigManager::Create("");

		instance.mLogger			= Logger::Create();

		instance.mWindowAPI			= WindowAPI::Create(WindowAPIType::GLFW);
		instance.mWindowContext		= WindowAPI::CreateContext();
		WindowAPI::MakeContextCurrent(instance.mWindowContext);

		instance.mRenderAPI			= RenderAPI::Create(RenderAPIType::OpenGL);
		instance.mRenderContext		= RenderAPI::CreateContext();
		RenderAPI::MakeContextCurrent(instance.mRenderContext);

		instance.mImGuiAPI			= ImGuiAPI::Create();
		instance.mImGuiContext		= ImGuiAPI::CreateContext();
		ImGuiAPI::MakeContextCurrent(instance.mImGuiContext);
	}

	void GlobalContext::Shutdown()
	{
		auto& instance = Get();

		ImGuiAPI::DestoryContext(instance.mImGuiContext);
		instance.mImGuiContext.reset();
		instance.mImGuiAPI.reset();

		RenderAPI::DestoryContext(instance.mRenderContext);
		instance.mRenderContext.reset();
		instance.mRenderAPI.reset();

		WindowAPI::DestoryContext(instance.mWindowContext);
		instance.mWindowContext.reset();
		instance.mWindowAPI.reset();

		instance.mLogger.reset();

		instance.mConfigManager.reset();
	}
} // !namespace SE